perm filename TANGLE.CH[WEB,DEK]5 blob sn#649970 filedate 1982-03-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00008 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00003 00002	@ Some of this code is optional for use when debugging only
C00005 00003	@ Here now is the system-dependent part of the character set.
C00006 00004	@ The following code opens the input files. Since these files were listed
C00008 00005	@ The following code opens |pascal_file| and |pool|. Since these files
C00009 00006	@ Input goes into an array called |buffer|.
C00010 00007	@p function input_ln(var f:text_file):boolean
C00012 00008	@<Print error location based on input buffer@>=
C00014 ENDMK
C⊗;
@ Some of this code is optional for use when debugging only;
such material is enclosed between the delimiters |debug| and $|gubed|$.
Other parts, delimited by |stat| and $|tats|$, are optionally included if
statistics about \.{TANGLE}'s memory usage are desired.

@d debug==@{ {change this to `$\\{debug}\eqv\null$' when debugging}
@d gubed==@} {change this to `$\\{gubed}\eqv\null$' when debugging}
@f debug==begin
@f gubed==end
@#
@d stat== {change this to `$\\{stat}\eqv\.{@@\}}$' when not
	gathering usage statistics}
@d tats== {change this to `$\\{tats}\eqv\.{@@\}}$' when not
	gathering usage statistics}
@f stat==begin
@f tats==end
@↑system dependencies@>@↑changes for {\mc SAIL}@>@z
@ Here now is the system-dependent part of the character set.
The code shown here is intended to be used on the Stanford {\sc SAIL} system,
and at other installations like CMU and ISI where essentially the same
extended character set is used. The fact that {\sc SAIL} has |'}'| in the
wrong place turns out to cause no difficulty in this case.

@<Set initial values...@>=
for i←1 to @'37 do xchr[i]←chr(i);
xchr[left_arrow]←chr(@'137);
xchr[not_equal]←chr(@'33);
xchr[@'33]←chr(@'176);
@↑system dependencies@>@↑changes for {\mc SAIL}@>@z
@ The following code opens the input files. Since these files were listed
in the program header, we assume that the \PASCAL\ runtime system has
already checked that suitable file names have been given; therefore
no additional error checking needs to be done. We open the files
in a special mode that allows us to distinguish |form_feed| from
|carriage_return|. Furthermore we specify nineteen input buffers, since
{\mc SAIL} folklore asserts that that is the most efficient procedure on
this system.

@p procedure open_input; {prepare to read |web_file| and |change_file|}
begin reset(web_file,'','/E/N:19'); reset(change_file,'','/E/N:19');
end;
@↑system dependencies@>@↑changes for {\mc SAIL}@>@z
@ The following code opens |pascal_file| and |pool|. Since these files
were listed in the program header, we assume that the \PASCAL\ runtime
system has checked that suitable external file names have been given.
@↑system dependencies@>

@<Set init...@>=
rewrite(pascal_file,'','/N:19'); rewrite(pool,'','/N:19');
@↑system dependencies@>@↑changes for {\mc SAIL}@>@z
@ Input goes into an array called |buffer|.
We use a special feature of the local \PASCAL\ that
reads text into another array |aux_buffer| first, thus saving
a bunch of procedure-call overhead.

@<Globals...@>=@!buffer: array[0..buf_size] of ascii_code;
@!aux_buffer:array[0..buf_size] of text_char;
@↑system dependencies@>@↑changes for {\mc SAIL}@>@z
@p function input_ln(var f:text_file):boolean;
	{inputs a line or returns |false|}
label restart;
var n: integer; {the number of characters input by Hedrick's extended |read|}
@!k:0..buf_size; {index into the buffers}
begin restart: if eof(f) then
	begin limit←0; input_ln←false;
	end
else	begin read(f,aux_buffer:n);
	if (line=1)∧(n=29)∧(aux_buffer[0]='C')∧(aux_buffer[8]=chr(@'26)) then
		begin while (f↑≠chr(form_feed))∧(not eof(f)) do
			begin read_ln(f);
			read(f,aux_buffer:n); {skip file directory page}
			end;
		end;
	if n<buf_size then
		begin limit←n;
		if n>0 then for k←0 to limit-1 do buffer[k]←xord[aux_buffer[k]]
		else if f↑=chr(form_feed) then
			begin line←((line div @'200000)+1)*@'200000+1;
			read_ln(f); goto restart;
			end;
		end
	else	begin limit←buf_size-1;
		for k←0 to limit-1 do buffer[k]←xord[aux_buffer[k]];
		print_nl('! Input line too long'); error;
@.Input line too long@>
		while not eoln(f) do read(f,aux_buffer);
		end;
	read_ln(f); input_ln←true;
	end;
end;
@↑system dependencies@>@↑changes for {\mc SAIL}@>@z
@<Print error location based on input buffer@>=
begin if changing then print('. (change file ')@+else print('. (');
print_ln('p.',1+(line div @'200000):0,',l.', line mod @'200000:0, ')');
if loc≥limit then l←limit else l←loc;
for k←1 to l do
	if buffer[k-1]=tab_mark then print(' ')
	else print(xchr[buffer[k-1]]); {print the characters already read}
new_line;
for k←1 to l do print(' '); {space out the next line}
for k←l+1 to limit do print(xchr[buffer[k-1]]); {print the part not yet read}
print(' '); {this space separates the message from future asterisks}
end

@↑system dependencies@>@↑changes for {\mc SAIL}@>@z